﻿using MediatR;
using SqliteApply.Common.Infrastructure.Interface;
using SqliteApply.Common.Table;
using SqliteApply.Enum;

namespace SqliteApply.Addlication.SqliteW
{
    public class UserCreateHandler : IRequestHandler<UserCreateCommon, Result>
    {
        public readonly IBaseRepository<Login> LoginRepository;

        public UserCreateHandler(IBaseRepository<Login> loginRepository)
        {
            LoginRepository = loginRepository;
        }

        public async Task<Result> Handle(UserCreateCommon request, CancellationToken cancellationToken)
        {
           var res = new Result() { code=1,msg= "新增失败" };
            try
            {
                var result = new Login()
                {
                    LoginName= request.LoginName,
                    LoginPassword= request.LoginPassword,
                };
                LoginRepository.Add(result);
                res.code = 0;
                res.msg = "新增成功";
            }
            catch (Exception)
            {

                throw;
            }
            return res;
        }
    }
}
